package com.hj.controller;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ConcentrateController {

	//事后专注度所需参数
	@RequestMapping("/concentration")
	public void concentration(HttpServletRequest request, HttpServletResponse response)throws Exception {
		
		//1.获取视频id
		String id = request.getParameter("videoId");
		int videoId=Integer.parseInt(id);
		//2.获取页面停留的时间
		String count1 = request.getParameter("count1");
		//3.获取中断次数
		String breakNum = request.getParameter("breakNum");
		//4.获取点赞数
		
		//5.获取视频观看次数
						
		//6.获取当前用户名
		String username = request.getParameter("username");		
		// 文件保存路径
		String path = "E:\\stayTime";
		// 如果路径文件夹目录不存在 创建。
		File file = new File(path);
		file.mkdirs(); 
		
        File f = new File(path + "\\"+ username + ".txt");      
        if (!f.exists())   
        {       
            f.createNewFile();      
        }      
        OutputStreamWriter ops = new OutputStreamWriter(new FileOutputStream(f),"utf-8");      
        BufferedWriter writer=new BufferedWriter(ops); 
        String str = videoId + "," + count1 + "," + breakNum + "";
        writer.write(str);      
        writer.close();     
	     
		
	}
}
